package api

import (
	"batbat-backend/app/model"
	"batbat-backend/app/service"
	"batbat-backend/library/response"
	"github.com/gogf/gf/net/ghttp"
)

// Category 种类API接口
var Category = categoryApi{}

type categoryApi struct{}

// Hot
// @summary 获取热门的8个游戏种类
// @tags    游戏种类
// @produce json
// @success 200 {object} response.JsonResponse{data=[]model.Category}
// @router  /category/hot [GET]
func (c *categoryApi) Hot(r *ghttp.Request) {
	categories, err := service.Category.GetAllCategory(r.Context())
	if err != nil {
		response.Error(r, err)
	}
	response.Success(r, categories)
}

// Games
// @summary 获取游戏种类下的游戏
// @tags    游戏种类
// @param	id path int true "要查询的分类"
// @param	pn query int false "页码, 默认为1"
// @param	limit query int false "每页显示的个数, 取值范围为10到30, 默认为15"
// @produce json
// @success 200 {object} response.JsonResponse{data=model.CategoryApiGamesResp}
// @router  /category/{id} [GET]
func (c *categoryApi) Games(r *ghttp.Request) {
	var req *model.CategoryApiGamesReq
	err := r.Parse(&req)
	if err != nil {
		response.Error(r, err)
	}
	resp, err := service.Category.Games(r.Context(), req.Id, req.Pn, req.Limit)
	if err != nil {
		response.Error(r, err)
	}
	response.Success(r, resp)
}
